package com.lvy.hczn.front.business.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lvy.hczn.front.business.service.ExceptionService;
import com.lvy.hczn.front.business.util.ResultUtil;
import com.lvy.hczn.front.system.domain.business.PurchaseOrderDetail;
import com.lvy.hczn.front.business.dto.Param;
import com.lvy.hczn.front.business.service.PurchaseOrderDetailService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/wcs/order/detail/")
@RestController
@Slf4j
public class PurchaseOrderDetailController {

    @Autowired
    private PurchaseOrderDetailService purchaseOrderDetailService;

    @Autowired
    private ExceptionService exceptionService;

    @ApiOperation(value = "分拣加工任务", notes = "分拣加工任务")
    @PostMapping("selectByCode")
    public List<PurchaseOrderDetail> selectByPurchaseOrderCode(@RequestBody Param param) {
        try {
            List<PurchaseOrderDetail> list = purchaseOrderDetailService.list(Wrappers.<PurchaseOrderDetail>lambdaQuery().eq(PurchaseOrderDetail::getPurchaseOrderCode, param.getPurchaseOrderCode()));
            return list;
        } catch (Exception e) {
            log.error("sorting error:{}", e);
            return null;
        }
    }

    @ApiOperation(value = "货箱缺失", notes = "配送时，缺少货箱操作")
    @PostMapping("boxLost")
    public ResultUtil boxLost(@RequestBody PurchaseOrderDetail purchaseOrderDetail) {
        try {
            return ResultUtil.ok(exceptionService.boxLost(purchaseOrderDetail));
        } catch (Exception e) {
            log.error("boxLost:{}", e);
            return ResultUtil.failed("系统异常");
        }
    }
}
